/**********************************************************************
 Copyright (C) 2010 Teppo Eeva

 This file is part of Arithmetic Game.
 For more information, see <http://code.google.com/p/arithmetic-game/>

 Arithmetic Game is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation, either version 3 of the License, or
 (at your option) any later version.

 Arithmetic Game is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with Arithmetic Game.  If not, see <http://www.gnu.org/licenses/>.
 **********************************************************************/

#include <QtTest/QtTest>
#include <QDebug>

#include "highscoreitem.h"


class TestHighScoreItem : public QObject
{
    Q_OBJECT

private slots:
    // Setup test case
    void initTestCase();

    // Actual test cases
    void doTest1_data();// Test data..
    void doTest1();     // Test focus: HighScoreItem::HighScoreItem(QString name, int score, int level)
    void doTest2();     // Test focus: HighScoreItem::HighScoreItem(const HighScoreItem &other)
    void doTest3();     // Test focus: HighScoreItem& HighScoreItem::operator=(const HighScoreItem &other)
    void doTest4();     // Test focus: bool HighScoreItem::operator==(const HighScoreItem &other)
    void doTest5();     // Test focus: bool HighScoreItem::operator!=(const HighScoreItem &other)
    void doTest6();     // Test focus: Difference in unique hash

    // Cleanup test case
    void cleanupTestCase();

private:

};


void TestHighScoreItem::initTestCase()
{
    qDebug() << "-- START -- TestHighScoreItem";
}

void TestHighScoreItem::cleanupTestCase()
{
    qDebug() << "-- END -- TestHighScoreItem";
}

void TestHighScoreItem::doTest1_data()
{
    // Columns defined in here.
    QTest::addColumn<QString>("name");
    QTest::addColumn<int>("score");
    QTest::addColumn<int>("level");

    // Created TCs for doTest1
    QTest::newRow("Veikko,55,5,True") << QString("Veikko") << 55 << 5; // << True;
    QTest::newRow("Heikko,0,0,True") << QString("Heikko") << 0 << 0; // << True;
}
void TestHighScoreItem::doTest1()
{
    // Test focus: HighScoreItem::HighScoreItem(QString name, int score, int level):
    QFETCH(QString, name);
    QFETCH(int, score);
    QFETCH(int, level);
    HighScoreItem q1(name, score, level);
    QVERIFY (q1.m_name == name);
    QVERIFY (q1.m_score == score);
    QVERIFY (q1.m_level == level);
    QVERIFY (!q1.uniqueHash().isEmpty()); // Hash value is calculated automatically based on values and the timestamp
    qDebug() << "doTest1: HighScoreItem :" << q1.m_name << ", " << q1.m_score << ", " << q1.m_level;
}

void TestHighScoreItem::doTest2()
{
    // Test focus: HighScoreItem::HighScoreItem(const HighScoreItem &other)
    HighScoreItem q1("Jorma", 66, 6);
    HighScoreItem q2(q1);
    qDebug() << "q1: " << q1;
    qDebug() << "q2: " << q2;
    QVERIFY (q2.m_name == q1.m_name);
    QVERIFY (q2.m_score == q1.m_score);
    QVERIFY (q2.m_level == q1.m_level);
    QVERIFY (q2.uniqueHash() == q1.uniqueHash());
}

void TestHighScoreItem::doTest3()
{
    // Test focus: HighScoreItem& HighScoreItem::operator=(const HighScoreItem &other)
    HighScoreItem q1("Item1", 33, 3);
    HighScoreItem q2("Item2", 34, 4);
    qDebug() << "Before assignment - q1:" << q1;
    qDebug() << "Before assignment - q2:" << q2;
    QVERIFY ( q2 != q1 );
    q2 = q1; // Values in q1 are copied to q2
    qDebug() << "After assignment - q1:" << q1;
    qDebug() << "After assignment - q2:" << q2;
    QVERIFY ( q2 == q1 );
}

void TestHighScoreItem::doTest4()
{
    // Test focus: bool HighScoreItem::operator==(const HighScoreItem &other)
    HighScoreItem q1("Helmi", 44, 4);
    HighScoreItem q2( q1 );

    qDebug() << "q1:" << q1;
    qDebug() << "q2:" << q2;
    QVERIFY (q2 == q1);
}

void TestHighScoreItem::doTest5()
{
    // Test focus: bool HighScoreItem::operator!=(const HighScoreItem &other)
    HighScoreItem q1("Helmi", 44, 4);
    HighScoreItem q2("Helmi", 45, 4);

    qDebug() << "q1:" << q1;
    qDebug() << "q2:" << q2;
    QVERIFY ( q2 != q1 );
}

void TestHighScoreItem::doTest6()
{
    // Test focus: Difference in unique hash
    HighScoreItem q1("Helmi", 44, 4);
    QTest::qWait(1000); // Wait 1 sec so that time stamp for hash values are different
    HighScoreItem q2("Helmi", 44, 4);

    qDebug() << "q1:" << q1 << " uniqueHash: " << q1.uniqueHash();
    qDebug() << "q2:" << q2 << " uniqueHash: " << q2.uniqueHash();
    QVERIFY ( q2 != q1 ); // Items are not same because the hash is different
}


QTEST_MAIN(TestHighScoreItem)
#include "testhighscoreitem.moc"
